import 'package:concierge/app/common/app_theme.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class Button extends StatelessWidget {
  final String text;
  final bool isEnabled; // 按钮是否启用，由外部控制
  final VoidCallback? onButtonPressed; // 按钮点击时的回调

  const Button(
    this.text, {
    Key? key,
    required this.isEnabled, // 接收外部传入的状态
    this.onButtonPressed, // 按钮点击事件
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      child: TextButton(
        onPressed: isEnabled ? onButtonPressed : null, // 根据外部状态控制
        style: ButtonStyle(
          padding: WidgetStateProperty.all<EdgeInsets>(
            EdgeInsets.symmetric(vertical: 11.0, horizontal: 0.0),
          ),
          backgroundColor: WidgetStateProperty.resolveWith<Color>((
            Set<WidgetState> states,
          ) {
            if (states.contains(WidgetState.disabled)) {
              return context.theme.colorScheme.tertiaryContainer; // 禁用时背景色
            }
            return context.theme.colorScheme.primary; // 启用时背景色
          }),
          /*foregroundColor: MaterialStateProperty.resolveWith<Color>(
            (Set<MaterialState> states) {
              if (states.contains(MaterialState.disabled)) {
                return context.common.colorScheme.secondary; // 禁用时文字颜色
              }
              return context.common.colorScheme.tertiaryContainer; // 启用时文字颜色
            },
          ),*/
          shape: WidgetStateProperty.all<RoundedRectangleBorder>(
            RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(AppTheme.cornerLarge), // 圆角
            ),
          ),
        ),
        child: Text(
          text,
          style: context.theme.textTheme.headlineMedium?.copyWith(
            color: isEnabled
                ? context.theme.colorScheme.primaryContainer
                : context.theme.colorScheme.secondary,
          ),
        ),
      ),
    );
  }
}
